package controller.user;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.UserDTO;
import bizlogic.UserManager;

public class ManageUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public ManageUserServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doProcess(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doProcess(request, response);
	}
	
	private void doProcess(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		UserManager um = new UserManager();
		UserDTO[] data = um.findAllManagers();
		request.setAttribute("managers", data);
		request.setAttribute("managerName", request.getParameter("managerName"));
		request.setAttribute("type", request.getParameter("role"));
		request.setAttribute("check", request.getParameter("status"));
		RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/ManageStaff.jsp");
		try {
			rd.forward(request, response);
		} catch (ServletException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
